package com.pioneer.cloudstorage.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pioneer.cloudstorage.pojo.entity.FileMetadata;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface FilesMapper extends BaseMapper<FileMetadata> {
    @Select("SELECT * FROM file_metadata WHERE user_id = #{userId} AND file_md5 = #{fileMd5} AND status = 1 LIMIT 1")
    FileMetadata selectByUserIdAndMd5(@Param("userId") Long userId, @Param("fileMd5") String fileMd5);

    @Select("SELECT COUNT(*) FROM file_metadata WHERE user_id = #{userId} AND file_name = #{fileName} AND parent_id = #{parentId} AND status = 1")
    int countSameNameFile(@Param("userId") Long userId, @Param("fileName") String fileName, @Param("parentId") Long parentId);
}
